package com.helloworld.demo.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockTest1 {

    private static Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        method1();
    }

    public static void method1(){
        lock.lock();
        try{
            System.out.println("excute method1");
            method2();
        }finally {
            lock.unlock();
        }
    }

    public static void method2(){
        lock.lock();
        try{
            System.out.println("excute method2");
            method3();
        }finally {
            lock.unlock();
        }
    }

    public static void method3(){
        lock.lock();
        try{
            System.out.println("excute method3");
        }finally {
            lock.unlock();
        }
    }

}
